﻿using CIS.DB;
using CIS.Web.Common;
using CIS.Web.Models;
using CIS.Web.Properties;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.IO;
using System.Linq;
using System.Linq.Dynamic;
using System.Threading.Tasks;
using System.Web.Mvc;
using static System.Net.Mime.MediaTypeNames;

namespace CIS.Web.Controllers
{
	[RoutePrefix("ConferenceContributeInfo")]
	public class ConferenceContributeInfoController : BaseDbController
	{
		private string _importMessage;

		[Route("Index/{ConferenceId}")]
		public async Task<ActionResult> Index(string conferenceId)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", conferenceId);

			var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
						x.ID == conferenceId);

			ViewBag.ConferenceId = conferenceId;
			ViewBag.ConferenceName = conferenceMaster.ConferenceName;
			ViewBag.ControllerName = Resources.ConferenceContributeInfo;
			ViewBag.Language = conferenceMaster.IsInternational ? ConstValues.Language.En : ConstValues.Language.Cn;

			var model = new ConferenceContributeInfoModel();
			model.ConferenceId = conferenceId;
			model.IsReview = conferenceMaster.IsReview;
			model.Form = Utility.GetContributeItem(conferenceId);
			LoginUser.ConferenceFunctionIdList = Utility.GetConferenceFunctionIdList(conferenceId);
			return View(model);
		}

		public async Task<JsonCamelCaseResult> GetData(int? page, int? rows, string sort, string order, ConferenceContributeInfoModel model)
		{
			int take = rows ?? ConstValues.DefaultGridRows;
			int skip = ((page ?? 1) - 1) * take;

			var sql = from info in DbContext.ConferenceContributeInfo.AsNoTracking().Where(x => x.ConferenceId == model.ConferenceId)
				  join topicMaster in DbContext.TopicMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					    on info.TopicId equals topicMaster.ID into t1
				  from topic in t1.DefaultIfEmpty()
				  join essayMaster in DbContext.EssayMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					    on info.EssayId equals essayMaster.ID into t2
				  from essay in t2.DefaultIfEmpty()
				  join reportMaster in DbContext.ReportMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					    on info.ReportId equals reportMaster.ID into t3
				  from report in t3.DefaultIfEmpty()
				  join ocisMaster in DbContext.OCISMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					    on info.OcisId equals ocisMaster.ID into t4
				  from ocis in t4.DefaultIfEmpty()
				  join journalMaster in DbContext.JournalMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					    on info.JournalId equals journalMaster.ID into t5
				  from journal in t5.DefaultIfEmpty()
				  select new
				  {
					  ID = info.ID,
					  ConferenceId = info.ConferenceId,
					  EssayTitle = info.EssayTitle,
					  Keyword = info.Keyword,
					  ProgramAbstract = info.ProgramAbstract,
					  Abstract = info.Abstract,
					  AbstractFile = info.AbstractFile,
					  SupplementaryFile = info.SupplementaryFile,
					  TopicId = info.TopicId,
					  EssayId = info.EssayId,
					  ReportId = info.ReportId,
					  OcisId = info.OcisId,
					  JournalId = info.JournalId,
					  TopicName = topic.TopicName,
					  EssayType = essay.EssayType,
					  ReportType = report.ReportType,
					  OCISName = ocis.OCISName,
					  JournalName = journal.JournalName,
					  ContributationStatus = info.ContributationStatus,
					  Sort = info.Sort,
					  Remark = info.Remark,
					  Creator = info.Creator,
					  CreateIP = info.CreateIP,
					  CreateDate = info.CreateDate,
					  AdminStatus = info.AdminStatus,
				  };

			if (!string.IsNullOrEmpty(model.SelTopic))
			{
				sql = sql.Where(x => x.TopicId == model.SelTopic);
			}

			if (!string.IsNullOrEmpty(model.SelReport))
			{
				sql = sql.Where(x => x.ReportId == model.SelReport);
			}

			if (!string.IsNullOrEmpty(model.SelEssay))
			{
				sql = sql.Where(x => x.EssayId == model.SelEssay);
			}

			if (!string.IsNullOrEmpty(model.SelJournal))
			{
				sql = sql.Where(x => x.JournalId == model.SelJournal);
			}

			if (!string.IsNullOrEmpty(model.SelContributationStatus))
			{
				sql = sql.Where(x => !string.IsNullOrEmpty(x.AdminStatus) ?
						x.AdminStatus == model.SelContributationStatus :
						x.ContributationStatus == model.SelContributationStatus);
			}

			if (!string.IsNullOrEmpty(model.SelIdName))
			{
				var contributeAuthorList = DbContext.AuthorInfo.AsNoTracking()
						.Where(x => x.ContributeId.Contains(model.SelIdName) ||
							x.FullName.Contains(model.SelIdName) ||
							x.Mobile.Contains(model.SelIdName) ||
							x.Mail.Contains(model.SelIdName))
						.Select(x => x.ContributeId)
						.ToList();

				var contributeAffiliationList = DbContext.AffiliationInfo.AsNoTracking()
						.Where(x => x.ContributeId.Contains(model.SelIdName) ||
							x.Mail.Contains(model.SelIdName) ||
							x.Affiliation.Contains(model.SelIdName))
						.Select(x => x.ContributeId)
						.ToList();

				sql = sql.Where(x => contributeAuthorList.Contains(x.ID) || contributeAffiliationList.Contains(x.ID));
			}

			int total = await sql.CountAsync();

			if (!string.IsNullOrEmpty(sort))
			{
				sql = sql.OrderBy(sort + ConstValues.chrSpace + order).Skip(skip).Take(take);
			}
			else
			{
				sql = sql.OrderByDescending(x => x.ID).Skip(skip).Take(take);
			}

			var sqlResult = await sql.ToListAsync();

			var result = sqlResult.Select(x => new
			{
				ID = x.ID,
				ConferenceId = x.ConferenceId,
				EssayTitle = x.EssayTitle,
				Keyword = x.Keyword,
				ProgramAbstract = x.ProgramAbstract,
				Abstract = x.Abstract,
				AbstractFile = string.IsNullOrEmpty(x.AbstractFile) ? string.Empty : Path.GetFileName(x.AbstractFile),
				SupplementaryFile = string.IsNullOrEmpty(x.SupplementaryFile) ? string.Empty : Path.GetFileName(x.SupplementaryFile),
				AbstractFilePath = string.IsNullOrEmpty(x.AbstractFile) ? string.Empty : ConstValues.SystemWeb + x.AbstractFile.Replace(ConstValues.strWave, string.Empty),
				SupplementaryFilePath = string.IsNullOrEmpty(x.SupplementaryFile) ? string.Empty : ConstValues.SystemWeb + x.SupplementaryFile.Replace(ConstValues.strWave, string.Empty),
				TopicName = x.TopicName,
				EssayType = x.EssayType,
				ReportType = x.ReportType,
				OCISName = x.OCISName,
				JournalName = x.JournalName,
				ContributationStatus = x.ContributationStatus,
				AdminStatus = x.AdminStatus,
				Sort = x.Sort,
				Remark = x.Remark,
				Creator = x.Creator,
				CreateIP = x.CreateIP,
				CreateDate = Request.Cookies["_culture"].Value == ConstValues.Language.Cn ?
							x.CreateDate.Value.ToString("yyyy-MM-dd") :
							x.CreateDate.Value.ToString("MM/dd/yyyy")
			});

			return JsonCamelCase(new
			{
				Total = total,
				Rows = result,
			},
			JsonRequestBehavior.AllowGet);
		}

		public async Task<JsonCamelCaseResult> GetEditData(string id)
		{
			var sqlResult = await DbContext.ConferenceContributeInfo.AsNoTracking()
					.FirstOrDefaultAsync(x => x.ID == id);

			var result = new
			{
				EssayTitle = sqlResult.EssayTitle,
				Keyword = sqlResult.Keyword,
				ProgramAbstract = sqlResult.ProgramAbstract,
				Abstract = sqlResult.Abstract,
				AbstractFile = Path.GetFileName(sqlResult.AbstractFile),
				SupplementaryFile = Path.GetFileName(sqlResult.SupplementaryFile),
				TopicId = sqlResult.TopicId,
				EssayId = sqlResult.EssayId,
				ReportId = sqlResult.ReportId,
				OcisId = sqlResult.OcisId,
				JournalId = sqlResult.JournalId,
				ContributationStatus = !string.IsNullOrEmpty(sqlResult.AdminStatus) ? sqlResult.AdminStatus : sqlResult.ContributationStatus,
				Sort = sqlResult.Sort,
				Remark = sqlResult.Remark
			};

			if (result == null)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(),
						JsonRequestBehavior.AllowGet);
			}

			if (result != null)
			{
				return JsonCamelCase(Utility.CreateSuccessJsonResult(string.Empty, result),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("Modify/{ConferenceId}")]
		[ValidateInput(false)]
		public async Task<JsonResult> Modify(ConferenceContributeInfoModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			if (model.AbstractFile != null || model.SupplementaryFile != null)
			{
				var msg = await this.SaveFiles(model);
				if (!string.IsNullOrEmpty(msg))
				{
					return JsonCamelCase(Utility.CreateFailJsonResult(msg),
							JsonRequestBehavior.AllowGet);
				}
			}

			var result = await DbContext.ConferenceContributeInfo
					.FirstOrDefaultAsync(x => x.ID == model.ContributeId);

			var scheduleInfo = await DbContext.ScheduleInfo.AsNoTracking()
					.FirstOrDefaultAsync(x => x.ContributeId == model.ContributeId &&
						x.Status == ConstValues.ScheduleStatus.已安排);

			if (scheduleInfo != null && (result.TopicId != model.Topic || result.ReportId != model.Report))
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgScheduleCanNotModify),
						JsonRequestBehavior.AllowGet);
			}

			if (result != null)
			{
				if (result.EssayTitle != model.EssayTitle)
				{
					result.EssayTitle = model.EssayTitle;
				}
				if (result.Keyword != model.Keyword)
				{
					result.Keyword = model.Keyword;
				}
				if (result.ProgramAbstract != model.ProgramAbstract)
				{
					result.ProgramAbstract = model.ProgramAbstract;
				}
				if (result.Abstract != model.Abstract)
				{
					result.Abstract = model.Abstract;
				}
				if (!string.IsNullOrWhiteSpace(model.AbstractFilePath))
				{
					if (model.AbstractFilePath == ConstValues.clearFlg)
					{
						result.AbstractFile = string.Empty;
					}
					else
					{
						result.AbstractFile = model.AbstractFilePath;
					}
				}
				if (!string.IsNullOrWhiteSpace(model.SupplementaryFilePath))
				{
					if (model.SupplementaryFilePath == ConstValues.clearFlg)
					{
						result.SupplementaryFile = string.Empty;
					}
					else
					{
						result.SupplementaryFile = model.SupplementaryFilePath;
					}
				}
				if (result.TopicId != model.Topic)
				{
					result.TopicId = model.Topic;
				}
				if (result.EssayId != model.Essay)
				{
					result.EssayId = model.Essay;
				}
				if (result.ReportId != model.Report)
				{
					result.ReportId = model.Report;
				}
				if (result.OcisId != model.Ocis)
				{
					result.OcisId = model.Ocis;
				}
				if (result.JournalId != model.Journal)
				{
					result.JournalId = model.Journal;
				}

				result.Updater = LoginUser.UserName;
				result.UpdateIP = LoginUser.IP;
				result.UpdateDate = DateTime.Now;

				await DbContext.SaveChangesAsync();

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("Delete/{ConferenceId}")]
		public async Task<JsonResult> Delete(ConferenceContributeInfoModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var exist = await DbContext.ReviewInfo.AsNoTracking()
					.Where(x => x.ContributeId == model.Id)
					.ToListAsync();

			if (exist.Count > 0)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgReviewHasStart),
						JsonRequestBehavior.AllowGet);
			}

			var result = await DbContext.ConferenceContributeInfo
					.FirstOrDefaultAsync(x => x.ID == model.ContributeId);

			if (result != null)
			{
				using (var transaction = DbContext.Database.BeginTransaction())
				{
					DbContext.ConferenceContributeInfo.Remove(result);

					var authorInfoList = await DbContext.AuthorInfo
							.Where(x => x.ContributeId == model.ContributeId).ToListAsync();
					DbContext.AuthorInfo.RemoveRange(authorInfoList);

					var affiliationInfoList = await DbContext.AffiliationInfo
							.Where(x => x.ContributeId == model.ContributeId).ToListAsync();
					DbContext.AffiliationInfo.RemoveRange(affiliationInfoList);

					await DbContext.SaveChangesAsync();
					transaction.Commit();
				}

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessDelete),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("ChangeContactAuthor/{ConferenceId}")]
		public async Task<JsonResult> ChangeContactAuthor(ConferenceContributeInfoModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var result = await DbContext.AuthorInfo
					.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (result != null)
			{
				if (result.IsContactAuthor)
				{
					result.IsContactAuthor = false;
				}
				else
				{
					result.IsContactAuthor = true;
				}

				result.Updater = LoginUser.UserName;
				result.UpdateIP = LoginUser.IP;
				result.UpdateDate = DateTime.Now;

				await DbContext.SaveChangesAsync();

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("ChangePresenter/{ConferenceId}")]
		public async Task<JsonResult> ChangePresenter(ConferenceContributeInfoModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var result = await DbContext.AuthorInfo
					.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (result != null)
			{
				using (var transaction = DbContext.Database.BeginTransaction())
				{
					var authorInfo = DbContext.AuthorInfo.Where(x => x.ContributeId == result.ContributeId).ToList();
					foreach (var author in authorInfo)
					{
						if (author.ID == model.Id)
						{
							author.IsPresenter = true;
							author.Updater = LoginUser.UserName;
							author.UpdateIP = LoginUser.IP;
							author.UpdateDate = DateTime.Now;
						}
						else
						{
							author.IsPresenter = false;
							author.Updater = LoginUser.UserName;
							author.UpdateIP = LoginUser.IP;
							author.UpdateDate = DateTime.Now;
						}
					}
					await DbContext.SaveChangesAsync();
					transaction.Commit();
				}
				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("CreateAuthor/{ConferenceId}")]
		public async Task<JsonResult> CreateAuthor(AuthorModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var tmpName = !string.IsNullOrEmpty(model.FullName) ? model.FullName?.Trim() :
						Utility.SetFullName(model.FamilyName?.Trim(), model.FirstName?.Trim(),
							Request.Cookies["_culture"] != null && Request.Cookies["_culture"].Value == ConstValues.Language.En ?
							ConstValues.Language.En : ConstValues.Language.Cn);

			var result = await DbContext.AuthorInfo
					.FirstOrDefaultAsync(x => x.ConferenceId == model.ConferenceId &&
						x.ContributeId == model.ContributeId &&
						x.Mail == model.Mail);

			if (result != null)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgTheSameMail),
							JsonRequestBehavior.AllowGet);
			}

			using (var transaction = DbContext.Database.BeginTransaction())
			{
				var authorInfo = new AuthorInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.AuthorInfo),
					ConferenceId = model.ConferenceId,
					ContributeId = model.ContributeId,
					FamilyName = model.FamilyName?.Trim(),
					FirstName = model.FirstName?.Trim(),
					FullName = tmpName,
					Department = model.Department?.Trim(),
					Country = model.Country,
					State = model.State,
					City = model.City,
					Address = model.Address?.Trim(),
					ZipCode = model.ZipCode?.Trim(),
					Mobile = model.Mobile?.Trim(),
					Mail = model.Mail?.Trim(),
					CcMail = model.CcMail?.Trim(),
					SelfIntroduction = model.SelfIntroduction?.Trim(),
					Status = model.Status,
					Sort = model.Sort.HasValue ? model.Sort.Value : ConstValues.DefaultSort,
					Remark = model.Remark?.Trim(),
					Creator = LoginUser.UserName,
					CreateIP = LoginUser.IP,
					CreateDate = DateTime.Now
				};
				DbContext.AuthorInfo.Add(authorInfo);

				await this.UpdateAffiliation(model);

				await DbContext.SaveChangesAsync();
				transaction.Commit();
			}

			return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
					JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("EditAuthor/{ConferenceId}")]
		public async Task<JsonResult> EditAuthor(AuthorModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var tmpName = !string.IsNullOrEmpty(model.FullName) ? model.FullName?.Trim() :
						Utility.SetFullName(model.FamilyName?.Trim(), model.FirstName?.Trim(),
							Request.Cookies["_culture"] != null && Request.Cookies["_culture"].Value == ConstValues.Language.En ?
							ConstValues.Language.En : ConstValues.Language.Cn);

			var exist = await DbContext.AuthorInfo
					.FirstOrDefaultAsync(x => x.ID != model.Id &&
						x.ConferenceId == model.ConferenceId &&
						x.ContributeId == model.ContributeId &&
						x.Mail == model.Mail);

			if (exist != null)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgTheSameMail),
							JsonRequestBehavior.AllowGet);
			}

			var result = await DbContext.AuthorInfo.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (result != null)
			{
				using (var transaction = DbContext.Database.BeginTransaction())
				{
					result.FamilyName = model.FamilyName?.Trim();
					result.FirstName = model.FirstName?.Trim();
					result.FullName = tmpName;
					result.Department = model.Department?.Trim();
					result.Country = model.Country;
					result.State = model.State;
					result.City = model.City;
					result.Address = model.Address?.Trim();
					result.ZipCode = model.ZipCode?.Trim();
					result.Mobile = model.Mobile?.Trim();
					result.Mail = model.Mail?.Trim();
					result.CcMail = model.CcMail?.Trim();
					result.SelfIntroduction = model.SelfIntroduction?.Trim();
					result.Status = model.Status;
					result.Sort = model.Sort.HasValue ? model.Sort.Value : ConstValues.DefaultSort;
					result.Remark = model.Remark?.Trim();
					result.Updater = LoginUser.UserName;
					result.UpdateIP = LoginUser.IP;
					result.UpdateDate = DateTime.Now;

					model.OriginalMail = DbContext.AuthorInfo.AsNoTracking().FirstOrDefault(x => x.ID == model.Id).Mail;
					await this.UpdateAffiliation(model);

					await DbContext.SaveChangesAsync();
					transaction.Commit();
				}

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}

		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("DeleteAuthor/{ConferenceId}")]
		public async Task<JsonResult> DeleteAuthor(AuthorModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var authorCount = await DbContext.AuthorInfo.AsNoTracking()
					.CountAsync(x => x.ID != model.Id && x.ContributeId == model.ContributeId);

			if (authorCount == 0)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(string.Format(Resources.MsgIsEmpty, Resources.Author)),
						JsonRequestBehavior.AllowGet);
			}

			var result = await DbContext.AuthorInfo
					.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (result != null)
			{
				if (result.IsPresenter)
				{
					return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgIsPresenter),
						JsonRequestBehavior.AllowGet);
				}
				using (var transaction = DbContext.Database.BeginTransaction())
				{
					var contributeId = result.ContributeId;
					var conferenceId = result.ConferenceId;
					var id = result.ID;
					var mail = result.Mail;
					DbContext.AuthorInfo.Remove(result);
					var currentAuthor = DbContext.AuthorInfo.Where(x => x.ContributeId == contributeId && x.ConferenceId == conferenceId && x.ID != id).OrderBy(x => x.Sort).ThenBy(x => x.CreateDate).ToList();
					for (var i = 0; i < currentAuthor.Count; i++)
					{
						currentAuthor[i].Sort = i + 1;
					}
					var affiliationInfo = await DbContext.AffiliationInfo.Where(x => x.ConferenceId == conferenceId && x.ContributeId == contributeId && x.Mail == mail).ToListAsync();
					DbContext.AffiliationInfo.RemoveRange(affiliationInfo);
					await DbContext.SaveChangesAsync();
					transaction.Commit();
				}
				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessDelete),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("ApplyOrDecline/{ConferenceId}")]
		public async Task<JsonResult> ApplyOrDecline(ConferenceContributeInfoModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var result = await DbContext.ProfileAwardsInfo
					.FirstOrDefaultAsync(x => x.AwardsId == model.Id &&
						x.ContributeId == model.ContributeId &&
						x.UserName == LoginUser.UserName);

			if (result != null)
			{
				DbContext.ProfileAwardsInfo.Remove(result);
			}
			else
			{
				var profileAwardsInfo = new ProfileAwardsInfo()
				{
					ID = Utility.GetTableId(ConstValues.TableName.ProfileAwardsInfo),
					UserName = LoginUser.UserName,
					ContributeId = model.ContributeId,
					AwardsId = model.Id,
					Creator = LoginUser.UserName,
					CreateIP = LoginUser.IP,
					CreateDate = DateTime.Now
				};

				DbContext.ProfileAwardsInfo.Add(profileAwardsInfo);
			}

			await DbContext.SaveChangesAsync();

			return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
					JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		public async Task<FileResult> Export(string allId, string conferenceId)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", conferenceId);

			var ids = allId.Split(ConstValues.chrComma);
			var sql = from info in DbContext.ConferenceContributeInfo.AsNoTracking().Where(x => ids.Contains(x.ID.ToString()))
				  join conferenceMaster in DbContext.ConferenceMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
				    on info.ConferenceId equals conferenceMaster.ID
				  join topicMaster in DbContext.TopicMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					  on info.TopicId equals topicMaster.ID into t1
				  from topic in t1.DefaultIfEmpty()
				  join essayMaster in DbContext.EssayMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					  on info.EssayId equals essayMaster.ID into t2
				  from essay in t2.DefaultIfEmpty()
				  join reportMaster in DbContext.ReportMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					  on info.ReportId equals reportMaster.ID into t3
				  from report in t3.DefaultIfEmpty()
				  join ocisMaster in DbContext.OCISMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					  on info.OcisId equals ocisMaster.ID into t4
				  from ocis in t4.DefaultIfEmpty()
				  join journalMaster in DbContext.JournalMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					  on info.JournalId equals journalMaster.ID into t5
				  from journal in t5.DefaultIfEmpty()
				  select new
				  {
					  ID = info.ID,
					  ConferenceId = info.ConferenceId,
					  EssayTitle = info.EssayTitle,
					  Keyword = info.Keyword,
					  ProgramAbstract = info.ProgramAbstract,
					  Abstract = info.Abstract,
					  AbstractFile = info.AbstractFile,
					  SupplementaryFile = info.SupplementaryFile,
					  TopicId = info.TopicId,
					  EssayId = info.EssayId,
					  ReportId = info.ReportId,
					  OcisId = info.OcisId,
					  JournalId = info.JournalId,
					  TopicName = topic.TopicName,
					  EssayType = essay.EssayType,
					  ReportType = report.ReportType,
					  OCISName = ocis.OCISName,
					  JournalName = journal.JournalName,
					  ContributationStatus = !string.IsNullOrEmpty(info.AdminStatus) ? info.AdminStatus : info.ContributationStatus,
					  Sort = info.Sort,
					  Remark = info.Remark,
					  Creator = info.Creator,
					  CreateIP = info.CreateIP,
					  CreateDate = info.CreateDate,
					  ConferenceNickName = conferenceMaster.ConferenceNickName
				  };

			var result = await sql.ToListAsync();

			// 作者列表
			var authorList = await DbContext.AuthorInfo.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						ids.Contains(x.ContributeId.ToString()))
					.ToListAsync();

			// 单位列表
			var affiliationList = await DbContext.AffiliationInfo.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						ids.Contains(x.ContributeId.ToString()))
					.ToListAsync();

			// 评优活动列表
			var awardsNameList = await DbContext.ProfileAwardsInfo.AsNoTracking().Where(x => ids.Contains(x.ContributeId.ToString()))
					.Join(DbContext.AwardsMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常),
						profile => profile.AwardsId,
						award => award.ID,
						(profile, award) => new
						{
							ContributeId = profile.ContributeId,
							AwardsName = award.AwardsName
						}
					)
					.ToListAsync();

			// 期刊列表
			var journalMasterList = await DbContext.JournalMaster.AsNoTracking()
					.Where(x => x.ConferenceId == conferenceId)
					.ToListAsync();

			// 审稿列表
			var reviewList = await DbContext.ReviewInfo.AsNoTracking()
					.Where(x => x.ConferenceId == conferenceId &&
						x.Result != ConstValues.ContributationStatus.待审 &&
						!x.IsFinalReview &&
						ids.Contains(x.ContributeId.ToString()))
					.ToListAsync();

			var reviewMaxCount = 0;
			if (reviewList.Count > 0)
			{
				reviewMaxCount = reviewList
					.GroupBy(x => x.ContributeId)
					.Max(x => x.Count());
			}

			var export = Request.Cookies["_culture"].Value == ConstValues.Language.Cn ?
					Resources.export_contributeInfoCN : Resources.export_contributeInfoEN;

			XSSFWorkbook workbook;

			using (MemoryStream readStream = new MemoryStream(export))
			{
				workbook = new XSSFWorkbook(readStream);
				ISheet sheet = workbook.GetSheetAt(0);

				for (var index = 1; index <= reviewMaxCount; index++)
				{
					ICell cell = sheet.GetRow(0).CreateCell(21 + index);
					cell.SetCellValue("Rating" + index);
				}

				var count = 0;
				foreach (var model in result)
				{
					count += 1;
					IRow row = sheet.CreateRow(count);

					// 审核状态
					int column = 0;
					ICell cell = row.CreateCell(column);
					cell.SetCellValue(model.ContributationStatus);

					// 稿号
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.ID);

					// 论文题目
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.EssayTitle);

					//所有作者
					var allAuthor = authorList.Where(x => x.ContributeId == model.ID)
							.ToList()
							.OrderBy(x => x.Sort)
							.ThenByDescending(x => x.CreateDate)
							.ThenBy(x => x.FullName);

					//作者姓名
					var authorNameWithNumber = string.Empty;
					var authorMail = string.Empty;
					var authorMobile = string.Empty;
					List<int> superCountList = new List<int>(); //公司的上标位置list
					List<int> boldCountList = new List<int>(); //所有作者要变成粗体的位置list
					List<int> mailBoldCountList = new List<int>(); //所有邮箱要变成粗体的位置list
					List<int> mobileBoldCountList = new List<int>(); //所有手机要变成粗体的位置list
					List<string> allAffiliation = new List<string>();

					//循环每一个作者
					foreach (var x in allAuthor)
					{
						if (!string.IsNullOrEmpty(authorNameWithNumber))
						{
							authorNameWithNumber += ConstValues.chrSemicolon;
						}
						if (!string.IsNullOrEmpty(authorMail))
						{
							authorMail += ConstValues.chrSemicolon;
						}
						if (!string.IsNullOrEmpty(authorMobile))
						{
							authorMobile += ConstValues.chrSemicolon;
						}

						var affiliationInfo = affiliationList.Where(y => y.Status == ConstValues.Status.正常 &&
									y.ContributeId == model.ID &&
									y.Mail == x.Mail)
									.OrderBy(y => y.Sort)
									.ThenBy(y => y.CreateDate)
									.ToList();
						var tempName = x.FullName;
						//如果是报告人就把当前index记录下来
						if (x.IsPresenter)
						{
							boldCountList.Add(authorNameWithNumber.Length);
							mailBoldCountList.Add(authorMail.Length);
							mobileBoldCountList.Add(authorMobile.Length);
						}
						authorMail += x.Mail;
						authorMobile += x.Mobile;
						if (x.IsContactAuthor)
						{
							authorMail += ConstValues.strStar;
							authorMobile += ConstValues.strStar;
						}
						//有公司信息就拼上数字
						if (affiliationInfo.Count > 0)
						{
							var tempAffiliation = string.Empty;
							for (var i = 0; i < affiliationInfo.Count; i++)
							{
								if (!string.IsNullOrEmpty(tempAffiliation))
								{
									tempAffiliation += ConstValues.chrSemicolon;
								}

								if (!allAffiliation.Contains(affiliationInfo[i].Affiliation))
								{
									allAffiliation.Add(affiliationInfo[i].Affiliation);
								}
								int index = allAffiliation.IndexOf(affiliationInfo[i].Affiliation);

								tempAffiliation += (index + 1).ToString();
							}

							//记录下上标的启末index
							authorNameWithNumber += tempName;
							superCountList.Add(authorNameWithNumber.Length);
							authorNameWithNumber += tempAffiliation;
							//如果是通讯作者就拼上*
							if (x.IsContactAuthor)
							{
								authorNameWithNumber += ConstValues.strStar;
							}
							superCountList.Add(authorNameWithNumber.Length);
						}
						else
						{
							//记录下上标的启末index
							authorNameWithNumber += tempName;
							//如果是通讯作者就拼上*
							if (x.IsContactAuthor)
							{
								superCountList.Add(authorNameWithNumber.Length);
								authorNameWithNumber += ConstValues.strStar;
								superCountList.Add(authorNameWithNumber.Length);
							}
						}

						//如果是报告人就把当前index记录下来
						if (x.IsPresenter)
						{
							boldCountList.Add(authorNameWithNumber.Length);
							mailBoldCountList.Add(authorMail.Length);
							mobileBoldCountList.Add(authorMobile.Length);
						}
					}

					// 所有作者
					column++;
					cell = row.CreateCell(column);
					XSSFRichTextString text = new XSSFRichTextString(authorNameWithNumber);
					if (!string.IsNullOrEmpty(authorNameWithNumber))
					{
						IFont ft2 = workbook.CreateFont();
						ft2.Boldweight = (short)FontBoldWeight.Bold;
						ft2.FontName = "宋体";
						ft2.FontHeightInPoints = 11;
						for (var i = 0; i < boldCountList.Count() / 2; i++)
						{
							text.ApplyFont(boldCountList[2 * i], boldCountList[2 * i + 1], ft2);
						}

						IFont ft = workbook.CreateFont();
						ft.TypeOffset = FontSuperScript.Super;
						for (var i = 0; i < superCountList.Count() / 2; i++)
						{
							text.ApplyFont(superCountList[2 * i], superCountList[2 * i + 1], ft);
						}
						cell.SetCellValue(text);
					}
					else
					{
						cell.SetCellValue(authorNameWithNumber);
					}

					var strAllAffiliation = string.Empty;
					for (var index = 0; index < allAffiliation.Count(); index++)
					{
						if (!string.IsNullOrEmpty(strAllAffiliation))
						{
							strAllAffiliation += ConstValues.strSemicolon;
						}
						strAllAffiliation += (index + 1).ToString() + ConstValues.strDot;
						strAllAffiliation += allAffiliation[index];
					}

					//单位
					column++;
					cell = row.CreateCell(column);
					if (!string.IsNullOrEmpty(strAllAffiliation))
					{
						cell.SetCellValue(strAllAffiliation);
					}

					//邮箱
					column++;
					cell = row.CreateCell(column);
					XSSFRichTextString text3 = new XSSFRichTextString(authorMail);
					if (!string.IsNullOrEmpty(authorMail))
					{
						IFont ft3 = workbook.CreateFont();
						ft3.Boldweight = (short)FontBoldWeight.Bold;
						ft3.FontName = "宋体";
						ft3.FontHeightInPoints = 11;
						for (var i = 0; i < mailBoldCountList.Count() / 2; i++)
						{
							text3.ApplyFont(mailBoldCountList[2 * i], mailBoldCountList[2 * i + 1], ft3);
						}
						cell.SetCellValue(text3);
					}
					else
					{
						cell.SetCellValue(authorMail);
					}

					//所有手机
					column++;
					cell = row.CreateCell(column);
					XSSFRichTextString text4 = new XSSFRichTextString(authorMobile);
					if (!string.IsNullOrEmpty(authorMobile))
					{
						IFont ft4 = workbook.CreateFont();
						ft4.Boldweight = (short)FontBoldWeight.Bold;
						ft4.FontName = "宋体";
						ft4.FontHeightInPoints = 11;
						for (var i = 0; i < mobileBoldCountList.Count() / 2; i++)
						{
							text4.ApplyFont(mobileBoldCountList[2 * i], mobileBoldCountList[2 * i + 1], ft4);
						}
						cell.SetCellValue(text4);
					}
					else
					{
						cell.SetCellValue(authorMobile);
					}

					// 日程摘要
					column++;
					cell = row.CreateCell(column);
					if (!string.IsNullOrEmpty(model.ProgramAbstract))
					{
						cell.SetCellValue(Utility.ChangeSubSupForExcel(workbook, model.ProgramAbstract));
					}
					else
					{
						cell.SetCellValue(string.Empty);
					}

					// 全文摘要
					column++;
					cell = row.CreateCell(column);
					if (!string.IsNullOrEmpty(model.Abstract))
					{
						cell.SetCellValue(Utility.ChangeSubSupForExcel(workbook, model.Abstract));
					}
					else
					{
						cell.SetCellValue(string.Empty);
					}

					// 关键词
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Keyword);

					var folder = ConstValues.SystemWeb + ConstValues.Uploads.Replace(ConstValues.strWave, string.Empty) + model.ConferenceNickName;
					if (!string.IsNullOrEmpty(model.JournalId))
					{
						var journalMaster = journalMasterList.FirstOrDefault(x => x.ID == model.JournalId &&
									x.ConferenceId == model.ConferenceId);
						folder = folder + ConstValues.chrSlash + journalMaster.JournalId;
					}

					// 专题名称
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(!string.IsNullOrEmpty(model.TopicName) ? model.TopicName.ToString() : string.Empty);

					// 论文类型
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(!string.IsNullOrEmpty(model.EssayType) ? model.EssayType.ToString() : string.Empty);

					// 报告类型
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(!string.IsNullOrEmpty(model.ReportType) ? model.ReportType.ToString() : string.Empty);

					//评优活动
					var awardsNameInfo = awardsNameList.Where(x => x.ContributeId == model.ID)
							.Select(x => x.AwardsName)
							.ToList();

					//评优活动
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(string.Join(ConstValues.strSemicolon, awardsNameInfo));

					// OCIS名称
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(!string.IsNullOrEmpty(model.OCISName) ? model.OCISName.ToString() : string.Empty);

					// 期刊名称
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(!string.IsNullOrEmpty(model.JournalName) ? model.JournalName.ToString() : string.Empty);

					// 备注
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Remark);

					// 全文摘要文件
					column++;
					cell = row.CreateCell(column);
					if (!string.IsNullOrEmpty(model.AbstractFile))
					{
						FileInfo fi = new FileInfo(model.AbstractFile);
						XSSFHyperlink link = new XSSFHyperlink(HyperlinkType.Url);
						string fileFullPath = folder + ConstValues.chrSlash + fi.Name;
						link.Address = fileFullPath;
						cell.Hyperlink = link;
						cell.SetCellValue(fileFullPath);
					}

					// 全文文件
					column++;
					cell = row.CreateCell(column);
					if (!string.IsNullOrEmpty(model.SupplementaryFile))
					{
						FileInfo fi = new FileInfo(model.SupplementaryFile);
						XSSFHyperlink link = new XSSFHyperlink(HyperlinkType.Url);
						string fileFullPath = folder + ConstValues.chrSlash + fi.Name;
						link.Address = fileFullPath;
						cell.Hyperlink = link;
						cell.SetCellValue(fileFullPath);
					}

					// 创建者
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Creator);

					// 创建IP
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.CreateIP);

					// 创建日期
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(Request.Cookies["_culture"].Value == ConstValues.Language.Cn ?
							model.CreateDate.Value.ToString("yyyy-MM-dd") :
							model.CreateDate.Value.ToString("MM/dd/yyyy"));

					// Rating
					var reviewInfoList = reviewList.Where(x => x.ContributeId == model.ID)
							.OrderBy(x => x.ContributeId)
							.ThenBy(x => x.UpdateDate)
							.ToList();

					foreach (var reviewInfo in reviewInfoList)
					{
						column++;
						cell = row.CreateCell(column);
						cell.SetCellValue((reviewInfo.Evaluation.HasValue && reviewInfo.Evaluation != 0 ?
								reviewInfo.Evaluation.ToString() + ConstValues.chrSpace : string.Empty) + reviewInfo.Remark);
					}
				}
			}

			MemoryStream exportStream = new MemoryStream();
			workbook.Write(exportStream);
			exportStream.Flush();
			exportStream.Position = 0;

			return File(exportStream, Application.Octet,
					$"export_contributeInfo_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
		}

		[Route("DownloadImportTemplate/{conferenceId}")]
		public async Task<ActionResult> DownloadImportTemplate(string conferenceId)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", conferenceId);

			var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.ID == conferenceId);

			if (conferenceMaster.IsInternational)
			{
				return File(Resources.import_contributeInfoEN,
						"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
						$"import_contributeInfoEN.xlsx");
			}
			else
			{
				return File(Resources.import_contributeInfoCN,
						"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
						$"import_contributeInfoCN.xlsx");
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("Import/{ConferenceId}")]
		public async Task<JsonResult> Import(ConferenceContributeInfoModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			if (model.ImportFile != null && model.ImportFile.InputStream.Length > 0)
			{
				try
				{
					var result = await this.ImportData(model.ConferenceId, model.ImportFile.InputStream);

					if (!string.IsNullOrEmpty(_importMessage))
					{
						return JsonCamelCase(Utility.CreateFailJsonResult(_importMessage),
								JsonRequestBehavior.AllowGet, true);
					}
					else
					{
						return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessImport),
								JsonRequestBehavior.AllowGet, true);
					}
				}
				catch (Exception)
				{
					return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgFileError),
							JsonRequestBehavior.AllowGet, true);
				}
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgInvalidFile),
					JsonRequestBehavior.AllowGet, true);
			}
		}

		private async Task<int> ImportData(string conferenceId, Stream stream)
		{
			var conferenceInfo = await DbContext.ConferenceMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.ID == conferenceId);

			XSSFWorkbook workbook;
			workbook = new XSSFWorkbook(stream);

			ISheet sheet = workbook.GetSheetAt(0);
			int rowIndex = 0;
			int recordCount = 0;

			while (true)
			{
				var tmpMsg = string.Empty;
				try
				{
					rowIndex++;
					IRow row = sheet.GetRow(rowIndex);
					if (row == null)
					{
						break;
					}

					var model = new ConferenceContributeInfoModel()
					{
						ConferenceId = conferenceId
					};
					int columnIndex = 0;

					// 论文题目
					model.EssayTitle = Utility.ReadExcelField(row.GetCell(columnIndex));
					if (string.IsNullOrEmpty(model.EssayTitle))
					{
						continue;
					}
					else if (model.EssayTitle.Length > 500)
					{
						tmpMsg += string.Format(Resources.MsgImportMaxLength, model.EssayTitle, Resources.EssayTitle, 500) + "<br/>";
					}
					model.EssayTitle = model.EssayTitle.Replace(ConstValues.strHtmlEnter, string.Empty).Replace(ConstValues.strHtmlChengeLine, string.Empty);

					// 关键词
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Keyword = Utility.ReadExcelField(row.GetCell(columnIndex));
					}

					// 全文摘要
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Abstract = Utility.ReadExcelField(row.GetCell(columnIndex));
					}

					// 日程摘要
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.ProgramAbstract = Utility.ReadExcelField(row.GetCell(columnIndex));
					}

					// 专题名称
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.TopicName = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (string.IsNullOrEmpty(model.TopicName))
						{
							tmpMsg += string.Format(Resources.MsgImportNotExist, model.EssayTitle, Resources.TopicName) + "<br/>";
						}
						else if (model.TopicName.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.EssayTitle, Resources.TopicName, 100) + "<br/>";
						}
						else
						{
							var topicMaster = await DbContext.TopicMaster.AsNoTracking()
									.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId &&
										x.TopicName == model.TopicName);

							if (topicMaster == null)
							{
								tmpMsg += string.Format(Resources.MsgImportNotExist, model.EssayTitle, Resources.TopicName) + "<br/>";
							}
							else
							{
								model.Topic = topicMaster.ID;
							}
						}
					}
					else
					{
						tmpMsg += string.Format(Resources.MsgImportNotExist, model.EssayTitle, Resources.TopicName) + "<br/>";
					}

					// 论文类型
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.EssayType = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.EssayType.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.EssayTitle, Resources.EssayType, 100) + "<br/>";
						}
						else
						{
							var essayMaster = await DbContext.EssayMaster.AsNoTracking()
									.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId &&
										x.EssayType == model.EssayType);

							if (essayMaster != null)
							{
								model.Essay = essayMaster.ID;
							}
						}
					}

					// 报告类型
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.ReportType = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (string.IsNullOrEmpty(model.ReportType))
						{
							tmpMsg += string.Format(Resources.MsgImportNotExist, model.EssayTitle, Resources.ReportType) + "<br/>";
						}
						else if (model.ReportType.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.EssayTitle, Resources.ReportType, 100) + "<br/>";
						}
						else
						{
							var reportMaster = await DbContext.ReportMaster.AsNoTracking()
									.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId &&
										x.ReportType == model.ReportType);

							if (reportMaster == null)
							{
								tmpMsg += string.Format(Resources.MsgImportNotExist, model.EssayTitle, Resources.ReportType) + "<br/>";
							}
							else
							{
								model.Report = reportMaster.ID;
							}
						}
					}

					// OcisCode
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.OCISName = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.OCISName.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.EssayTitle, Resources.OCISName, 100) + "<br/>";
						}
						else
						{
							var ocisMaster = await DbContext.OCISMaster.AsNoTracking()
									.FirstOrDefaultAsync(x => x.OCISName == model.OCISName);

							if (ocisMaster != null)
							{
								model.Ocis = ocisMaster.ID;
							}
						}
					}

					// 目标期刊
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.JournalName = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.JournalName.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.EssayTitle, Resources.JournalName, 100) + "<br/>";
						}
						else
						{
							var journalMaster = await DbContext.JournalMaster.AsNoTracking()
									.FirstOrDefaultAsync(x => x.ConferenceId == conferenceId &&
										x.JournalName == model.JournalName);

							if (journalMaster != null)
							{
								model.Journal = journalMaster.ID;
							}
						}
					}

					// 报告人
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Presenter = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (string.IsNullOrEmpty(model.Presenter))
						{
							tmpMsg += string.Format(Resources.MsgImportNotExist, model.EssayTitle, Resources.Presenter) + "<br/>";
						}
						else if (model.Presenter.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.EssayTitle, Resources.Presenter, 100) + "<br/>";
						}
						else if (conferenceInfo.IsInternational && model.Presenter.LastIndexOf(ConstValues.chrSpace) < 0)
						{
							tmpMsg += string.Format(Resources.MsgImportNotCorrect, model.EssayTitle, Resources.Presenter) + "<br/>";
						}
					}
					else
					{
						tmpMsg += string.Format(Resources.MsgImportNotExist, model.EssayTitle, Resources.Presenter) + "<br/>";
					}

					// 单位
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Affiliation = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (string.IsNullOrEmpty(model.Affiliation))
						{
							tmpMsg += string.Format(Resources.MsgImportNotExist, model.EssayTitle, Resources.Affiliation) + "<br/>";
						}
					}
					else
					{
						tmpMsg += string.Format(Resources.MsgImportNotExist, model.EssayTitle, Resources.Affiliation) + "<br/>";
					}

					// 国家
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Country = Utility.ReadExcelField(row.GetCell(columnIndex));

						model.Country = model.Country.Replace('；', ConstValues.chrSemicolon);
						var countryList = model.Country.Split(ConstValues.chrSemicolon);

						if (string.IsNullOrEmpty(model.Country))
						{
							tmpMsg += string.Format(Resources.MsgImportNotExist, model.EssayTitle, Resources.Country) + "<br/>";
						}

						if (countryList.Length > 0)
						{
							var tempCountryName = countryList[0];
							var locationMaster = await DbContext.LocationMaster.AsNoTracking()
											.FirstOrDefaultAsync(x => x.Name == tempCountryName || x.NameEn == tempCountryName);
							if (locationMaster == null)
							{
								tmpMsg += string.Format(Resources.MsgImportNotExist, model.EssayTitle, Resources.Country) + "<br/>";
							}
						}
					}
					else
					{
						tmpMsg += string.Format(Resources.MsgImportNotExist, model.EssayTitle, Resources.Country) + "<br/>";
					}

					// 手机
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Mobile = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.Mobile.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.EssayTitle, Resources.Mobile, 100) + "<br/>";
						}
					}

					// 邮箱
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Mail = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (string.IsNullOrEmpty(model.Mail))
						{
							tmpMsg += string.Format(Resources.MsgImportNotExist, model.EssayTitle, Resources.Mail) + "<br/>";
						}
						else if (model.Mail.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.EssayTitle, Resources.Mail, 100) + "<br/>";
						}
					}
					else
					{
						tmpMsg += string.Format(Resources.MsgImportNotExist, model.EssayTitle, Resources.Presenter) + "<br/>";
					}

					// 自我介绍
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.SelfIntroduction = Utility.ReadExcelField(row.GetCell(columnIndex));
					}

					if (!string.IsNullOrEmpty(tmpMsg))
					{
						_importMessage += tmpMsg;
						continue;
					}

					#region ConferenceContributeInfo
					var conferenceContributeInfo = new ConferenceContributeInfo
					{
						ID = Utility.GetNewContributeId(conferenceId),
						ConferenceId = conferenceId,
						EssayTitle = model.EssayTitle,
						Keyword = model.Keyword,
						ProgramAbstract = model.ProgramAbstract,
						Abstract = model.Abstract,
						AbstractFile = string.Empty,
						SupplementaryFile = string.Empty,
						TopicId = model.Topic,
						EssayId = model.Essay,
						ReportId = model.Report,
						OcisId = model.Ocis,
						JournalId = model.Journal,
						HasSend = false,
						IsConfirm = false,
						ScheduleStatus = ConstValues.ScheduleStatus.无,
						ContributationStatus = ConstValues.ContributationStatus.待审,
						Sort = ConstValues.DefaultSort,
						Creator = LoginUser.UserName,
						CreateIP = LoginUser.IP,
						CreateDate = DateTime.Now
					};
					DbContext.ConferenceContributeInfo.Add(conferenceContributeInfo);
					#endregion

					#region AuthorInfo
					var authorInfo = new AuthorInfo
					{
						ID = Utility.GetTableId(ConstValues.TableName.AuthorInfo),
						ConferenceId = conferenceId,
						ContributeId = conferenceContributeInfo.ID,
						FirstName = conferenceInfo.IsInternational ?
								model.Presenter.Substring(0, model.Presenter.LastIndexOf(ConstValues.chrSpace)) : string.Empty,
						FamilyName = conferenceInfo.IsInternational ?
								model.Presenter.Substring(model.Presenter.LastIndexOf(ConstValues.chrSpace) + 1,
								model.Presenter.Length - model.Presenter.LastIndexOf(ConstValues.chrSpace) - 1) : model.Presenter,
						FullName = model.Presenter,
						Mobile = model.Mobile,
						Mail = model.Mail,
						IsFirstAuthor = false,
						IsContactAuthor = false,
						IsPresenter = true,
						SelfIntroduction = model.SelfIntroduction,
						Status = ConstValues.Status.正常,
						Sort = 1,
						Creator = LoginUser.UserName,
						CreateIP = LoginUser.IP,
						CreateDate = DateTime.Now
					};
					DbContext.AuthorInfo.Add(authorInfo);
					#endregion

					#region AffiliationInfo
					if (!string.IsNullOrEmpty(model.Affiliation))
					{
						var author = new AuthorModel
						{
							ConferenceId = conferenceId,
							ContributeId = conferenceContributeInfo.ID,
							Mail = model.Mail,
							Status = ConstValues.Status.正常
						};
						model.Affiliation = model.Affiliation.Replace('；', ConstValues.chrSemicolon);
						var affiliationList = model.Affiliation.Split(ConstValues.chrSemicolon);

						var countryList = model.Country.Split(ConstValues.chrSemicolon);
						var affiliationCount = 0;

						foreach (var affiliation in affiliationList)
						{
							if (!string.IsNullOrEmpty(affiliation) && affiliation.Length <= 100)
							{
								if (affiliationCount == 0)
								{
									author.Affiliation0 = affiliation;
									if (countryList.Length <= affiliationCount)
									{
										author.Country0 = null;
									}
									else
									{
										var tempCountryName = countryList[affiliationCount];
										var locationMaster = await DbContext.LocationMaster.AsNoTracking()
														.FirstOrDefaultAsync(x => x.Name == tempCountryName || x.NameEn == tempCountryName);
										if (locationMaster != null)
										{
											author.Country0 = locationMaster.ID;
										}
										else
										{
											author.Country0 = null;
										}
									}

								}
								else if (affiliationCount == 1)
								{
									author.Affiliation1 = affiliation;
									if (countryList.Length <= affiliationCount)
									{
										author.Country1 = null;
									}
									else
									{
										var tempCountryName = countryList[affiliationCount];
										var locationMaster = await DbContext.LocationMaster.AsNoTracking()
														.FirstOrDefaultAsync(x => x.Name == tempCountryName || x.NameEn == tempCountryName);
										if (locationMaster != null)
										{
											author.Country1 = locationMaster.ID;
										}
										else
										{
											author.Country1 = null;
										}
									}
								}
								else if (affiliationCount == 2)
								{
									author.Affiliation2 = affiliation;
									if (countryList.Length <= affiliationCount)
									{
										author.Country2 = null;
									}
									else
									{
										var tempCountryName = countryList[affiliationCount];
										var locationMaster = await DbContext.LocationMaster.AsNoTracking()
														.FirstOrDefaultAsync(x => x.Name == tempCountryName || x.NameEn == tempCountryName);
										if (locationMaster != null)
										{
											author.Country2 = locationMaster.ID;
										}
										else
										{
											author.Country2 = null;
										}
									}
								}
								else if (affiliationCount == 3)
								{
									author.Affiliation3 = affiliation;
									if (countryList.Length <= affiliationCount)
									{
										author.Country3 = null;
									}
									else
									{
										var tempCountryName = countryList[affiliationCount];
										var locationMaster = await DbContext.LocationMaster.AsNoTracking()
														.FirstOrDefaultAsync(x => x.Name == tempCountryName || x.NameEn == tempCountryName);
										if (locationMaster != null)
										{
											author.Country3 = locationMaster.ID;
										}
										else
										{
											author.Country3 = null;
										}
									}
								}
								else if (affiliationCount == 4)
								{
									author.Affiliation4 = affiliation;
									if (countryList.Length <= affiliationCount)
									{
										author.Country4 = null;
									}
									else
									{
										var tempCountryName = countryList[affiliationCount];
										var locationMaster = await DbContext.LocationMaster.AsNoTracking()
														.FirstOrDefaultAsync(x => x.Name == tempCountryName || x.NameEn == tempCountryName);
										if (locationMaster != null)
										{
											author.Country4 = locationMaster.ID;
										}
										else
										{
											author.Country4 = null;
										}
									}
								}
								else if (affiliationCount == 5)
								{
									author.Affiliation5 = affiliation;
									if (countryList.Length <= affiliationCount)
									{
										author.Country5 = null;
									}
									else
									{
										var tempCountryName = countryList[affiliationCount];
										var locationMaster = await DbContext.LocationMaster.AsNoTracking()
														.FirstOrDefaultAsync(x => x.Name == tempCountryName || x.NameEn == tempCountryName);
										if (locationMaster != null)
										{
											author.Country5 = locationMaster.ID;
										}
										else
										{
											author.Country5 = null;
										}
									}
								}
								else if (affiliationCount == 6)
								{
									author.Affiliation6 = affiliation;
									if (countryList.Length <= affiliationCount)
									{
										author.Country6 = null;
									}
									else
									{
										var tempCountryName = countryList[affiliationCount];
										var locationMaster = await DbContext.LocationMaster.AsNoTracking()
														.FirstOrDefaultAsync(x => x.Name == tempCountryName || x.NameEn == tempCountryName);
										if (locationMaster != null)
										{
											author.Country6 = locationMaster.ID;
										}
										else
										{
											author.Country6 = null;
										}
									}
								}
								else if (affiliationCount == 7)
								{
									author.Affiliation7 = affiliation;
									if (countryList.Length <= affiliationCount)
									{
										author.Country7 = null;
									}
									else
									{
										var tempCountryName = countryList[affiliationCount];
										var locationMaster = await DbContext.LocationMaster.AsNoTracking()
														.FirstOrDefaultAsync(x => x.Name == tempCountryName || x.NameEn == tempCountryName);
										if (locationMaster != null)
										{
											author.Country7 = locationMaster.ID;
										}
										else
										{
											author.Country7 = null;
										}
									}
								}
								else if (affiliationCount == 8)
								{
									author.Affiliation8 = affiliation;
									if (countryList.Length <= affiliationCount)
									{
										author.Country8 = null;
									}
									else
									{
										var tempCountryName = countryList[affiliationCount];
										var locationMaster = await DbContext.LocationMaster.AsNoTracking()
														.FirstOrDefaultAsync(x => x.Name == tempCountryName || x.NameEn == tempCountryName);
										if (locationMaster != null)
										{
											author.Country8 = locationMaster.ID;
										}
										else
										{
											author.Country8 = null;
										}
									}
								}
								else if (affiliationCount == 9)
								{
									author.Affiliation9 = affiliation;
									if (countryList.Length <= affiliationCount)
									{
										author.Country9 = null;
									}
									else
									{
										var tempCountryName = countryList[affiliationCount];
										var locationMaster = await DbContext.LocationMaster.AsNoTracking()
														.FirstOrDefaultAsync(x => x.Name == tempCountryName || x.NameEn == tempCountryName);
										if (locationMaster != null)
										{
											author.Country9 = locationMaster.ID;
										}
										else
										{
											author.Country9 = null;
										}
									}
								}
								affiliationCount += 1;
							}
						}

						await this.UpdateAffiliation(author);
					}
					#endregion

					await DbContext.SaveChangesAsync();

					recordCount++;
				}
				catch (Exception)
				{
					continue;
				}
			}

			return await Task.FromResult(recordCount);
		}

		private async Task<string> SaveFiles(ConferenceContributeInfoModel model)
		{
			string nickName = DbContext.ConferenceMaster.AsNoTracking().FirstOrDefault(x => x.ID == model.ConferenceId)?.ConferenceNickName;
			string folder = Path.Combine(ConstValues.Uploads, nickName);
			string pfolder = Path.Combine(Server.MapPath(ConstValues.Uploads), nickName);

			var journalId = string.Empty;
			if (!string.IsNullOrEmpty(model.Journal))
			{
				var journalMaster = await DbContext.JournalMaster.AsNoTracking()
						.FirstOrDefaultAsync(x => x.ID == model.Journal &&
							x.ConferenceId == model.ConferenceId);
				journalId = journalMaster.JournalId;
				folder = Path.Combine(folder, journalMaster.JournalId);
			}

			if (!string.IsNullOrEmpty(journalId))
			{
				pfolder = Path.Combine(pfolder, journalId);
			}

			if (model.AbstractFile != null)
			{
				if (model.AbstractFile.ContentLength > ConstValues.FileMaxLength)
				{
					return Resources.MsgFileOverflowError;
				}

				string fileName = nickName + ConstValues.strHyphen +
						Path.GetExtension(model.AbstractFile.FileName).Replace(".", "").ToUpper() + ConstValues.strHyphen +
						DateTime.Now.ToString("yyyy") + ConstValues.strHyphen +
						Utility.GetRandom() + Path.GetExtension(model.AbstractFile.FileName);
				model.AbstractFilePath = Path.Combine(folder, fileName);
				var saveFileTask = Task.Run(() =>
				{
					string pFullPath = Path.Combine(pfolder, fileName);
					if (!Directory.Exists(pfolder))
					{
						Directory.CreateDirectory(pfolder);
					}
					model.AbstractFile.SaveAs(pFullPath);
				});
				Task.WaitAll(saveFileTask);
			}

			if (model.SupplementaryFile != null)
			{
				if (model.SupplementaryFile.ContentLength > ConstValues.FileMaxLength)
				{
					return Resources.MsgFileOverflowError;
				}

				string fileName = nickName + ConstValues.strHyphen +
						Path.GetExtension(model.SupplementaryFile.FileName).Replace(".", "").ToUpper() + ConstValues.strHyphen +
						DateTime.Now.ToString("yyyy") + ConstValues.strHyphen +
						Utility.GetRandom() + Path.GetExtension(model.SupplementaryFile.FileName);
				model.SupplementaryFilePath = Path.Combine(folder, fileName);
				var saveFileTask = Task.Run(() =>
				{
					string pFullPath = Path.Combine(pfolder, fileName);
					if (!Directory.Exists(pfolder))
					{
						Directory.CreateDirectory(pfolder);
					}
					model.SupplementaryFile.SaveAs(pFullPath);
				});
				Task.WaitAll(saveFileTask);
			}
			return string.Empty;
		}

		private async Task UpdateAffiliation(AuthorModel model)
		{
			var mail = !string.IsNullOrEmpty(model.OriginalMail) ? model.OriginalMail : model.Mail;
			var affiliationList = await DbContext.AffiliationInfo
					.Where(x => x.ConferenceId == model.ConferenceId &&
						x.ContributeId == model.ContributeId &&
						x.Mail == mail)
					.ToListAsync();

			DbContext.AffiliationInfo.RemoveRange(affiliationList);

			var dt = DateTime.Now;

			#region 单位0
			if (!string.IsNullOrEmpty(model.Affiliation0))
			{
				var affiliationInfo = new AffiliationInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.AffiliationInfo),
					ConferenceId = model.ConferenceId,
					ContributeId = model.ContributeId,
					Mail = model.Mail?.Trim(),
					Affiliation = model.Affiliation0?.Trim(),
					Country = model.Country0,
					Status = model.Status,
					Sort = 0,
					Remark = model.Remark?.Trim(),
					Creator = LoginUser.UserName,
					CreateIP = LoginUser.IP,
					CreateDate = dt
				};
				DbContext.AffiliationInfo.Add(affiliationInfo);
			}
			#endregion
			#region 单位1
			if (!string.IsNullOrEmpty(model.Affiliation1))
			{
				var affiliationInfo = new AffiliationInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.AffiliationInfo),
					ConferenceId = model.ConferenceId,
					ContributeId = model.ContributeId,
					Mail = model.Mail?.Trim(),
					Affiliation = model.Affiliation1?.Trim(),
					Country = model.Country1,
					Status = model.Status,
					Sort = 1,
					Remark = model.Remark?.Trim(),
					Creator = LoginUser.UserName,
					CreateIP = LoginUser.IP,
					CreateDate = dt
				};
				DbContext.AffiliationInfo.Add(affiliationInfo);
			}
			#endregion
			#region 单位2
			if (!string.IsNullOrEmpty(model.Affiliation2))
			{
				var affiliationInfo = new AffiliationInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.AffiliationInfo),
					ConferenceId = model.ConferenceId,
					ContributeId = model.ContributeId,
					Mail = model.Mail?.Trim(),
					Affiliation = model.Affiliation2?.Trim(),
					Country = model.Country2,
					Status = model.Status,
					Sort = 2,
					Remark = model.Remark?.Trim(),
					Creator = LoginUser.UserName,
					CreateIP = LoginUser.IP,
					CreateDate = dt
				};
				DbContext.AffiliationInfo.Add(affiliationInfo);
			}
			#endregion
			#region 单位3
			if (!string.IsNullOrEmpty(model.Affiliation3))
			{
				var affiliationInfo = new AffiliationInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.AffiliationInfo),
					ConferenceId = model.ConferenceId,
					ContributeId = model.ContributeId,
					Mail = model.Mail?.Trim(),
					Affiliation = model.Affiliation3?.Trim(),
					Country = model.Country3,
					Status = model.Status,
					Sort = 3,
					Remark = model.Remark?.Trim(),
					Creator = LoginUser.UserName,
					CreateIP = LoginUser.IP,
					CreateDate = dt
				};
				DbContext.AffiliationInfo.Add(affiliationInfo);
			}
			#endregion
			#region 单位4
			if (!string.IsNullOrEmpty(model.Affiliation4))
			{
				var affiliationInfo = new AffiliationInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.AffiliationInfo),
					ConferenceId = model.ConferenceId,
					ContributeId = model.ContributeId,
					Mail = model.Mail?.Trim(),
					Affiliation = model.Affiliation4?.Trim(),
					Country = model.Country4,
					Status = model.Status,
					Sort = 4,
					Remark = model.Remark?.Trim(),
					Creator = LoginUser.UserName,
					CreateIP = LoginUser.IP,
					CreateDate = dt
				};
				DbContext.AffiliationInfo.Add(affiliationInfo);
			}
			#endregion
			#region 单位5
			if (!string.IsNullOrEmpty(model.Affiliation5))
			{
				var affiliationInfo = new AffiliationInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.AffiliationInfo),
					ConferenceId = model.ConferenceId,
					ContributeId = model.ContributeId,
					Mail = model.Mail?.Trim(),
					Affiliation = model.Affiliation5?.Trim(),
					Country = model.Country5,
					Status = model.Status,
					Sort = 5,
					Remark = model.Remark?.Trim(),
					Creator = LoginUser.UserName,
					CreateIP = LoginUser.IP,
					CreateDate = dt
				};
				DbContext.AffiliationInfo.Add(affiliationInfo);
			}
			#endregion
			#region 单位6
			if (!string.IsNullOrEmpty(model.Affiliation6))
			{
				var affiliationInfo = new AffiliationInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.AffiliationInfo),
					ConferenceId = model.ConferenceId,
					ContributeId = model.ContributeId,
					Mail = model.Mail?.Trim(),
					Affiliation = model.Affiliation6?.Trim(),
					Country = model.Country6,
					Status = model.Status,
					Sort = 6,
					Remark = model.Remark?.Trim(),
					Creator = LoginUser.UserName,
					CreateIP = LoginUser.IP,
					CreateDate = dt
				};
				DbContext.AffiliationInfo.Add(affiliationInfo);
			}
			#endregion
			#region 单位7
			if (!string.IsNullOrEmpty(model.Affiliation7))
			{
				var affiliationInfo = new AffiliationInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.AffiliationInfo),
					ConferenceId = model.ConferenceId,
					ContributeId = model.ContributeId,
					Mail = model.Mail?.Trim(),
					Affiliation = model.Affiliation7?.Trim(),
					Country = model.Country7,
					Status = model.Status,
					Sort = 7,
					Remark = model.Remark?.Trim(),
					Creator = LoginUser.UserName,
					CreateIP = LoginUser.IP,
					CreateDate = dt
				};
				DbContext.AffiliationInfo.Add(affiliationInfo);
			}
			#endregion
			#region 单位8
			if (!string.IsNullOrEmpty(model.Affiliation8))
			{
				var affiliationInfo = new AffiliationInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.AffiliationInfo),
					ConferenceId = model.ConferenceId,
					ContributeId = model.ContributeId,
					Mail = model.Mail?.Trim(),
					Affiliation = model.Affiliation8?.Trim(),
					Country = model.Country8,
					Status = model.Status,
					Sort = 8,
					Remark = model.Remark?.Trim(),
					Creator = LoginUser.UserName,
					CreateIP = LoginUser.IP,
					CreateDate = dt
				};
				DbContext.AffiliationInfo.Add(affiliationInfo);
			}
			#endregion
			#region 单位9
			if (!string.IsNullOrEmpty(model.Affiliation9))
			{
				var affiliationInfo = new AffiliationInfo
				{
					ID = Utility.GetTableId(ConstValues.TableName.AffiliationInfo),
					ConferenceId = model.ConferenceId,
					ContributeId = model.ContributeId,
					Mail = model.Mail?.Trim(),
					Affiliation = model.Affiliation9?.Trim(),
					Country = model.Country9,
					Status = model.Status,
					Sort = 9,
					Remark = model.Remark?.Trim(),
					Creator = LoginUser.UserName,
					CreateIP = LoginUser.IP,
					CreateDate = dt
				};
				DbContext.AffiliationInfo.Add(affiliationInfo);
			}
			#endregion
		}
	}
}